package com.ruyuan.eshop.common.domain.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruyuan.eshop.framework.domain.entity.BaseEntity;
import com.ruyuan.eshop.common.domain.vo.GoodsSkuVO;
import com.ruyuan.eshop.common.domain.vo.SpecValueVO;
import com.ruyuan.eshop.common.domain.vo.CartSkuVO;
import com.ruyuan.eshop.common.enums.CommentStatusEnum;
import com.ruyuan.eshop.framework.utils.JsonUtil;
import lombok.Data;

import java.util.List;


/**
 * 订单货物表实体
 * @author pwd
 * @version 1.0
 */
@Data
@TableName("es_order_items")
public class OrderItemsDO extends BaseEntity {

    /**商品ID*/
    @TableField(value = "goods_id")
    private Long goodsId;

    /**货品ID*/
    @TableField(value = "product_id")
    private Long productId;

    /**销售量*/
    @TableField(value = "num")
    private Integer num;

    /**发货量*/
    @TableField(value = "ship_num")
    private Integer shipNum;

    /**交易编号*/
    @TableField(value = "trade_sn")
    private String tradeSn;

    /**订单编号*/
    @TableField(value = "order_sn")
    private String orderSn;

    /**图片*/
    @TableField(value = "image")
    private String image;

    /**商品名称*/
    private String name;

    /**销售金额*/
    private Double price;

    /**分类ID*/
    private Long catId;

    /**状态*/
    private Integer state;

    /**快照id*/
    private Long snapshotId;

    /**规格json*/
    private String specJson;

    /**促销类型*/
    @TableField(value = "promotion_type")
    private String promotionType;

    /**促销id*/
    @TableField(value = "promotion_id")
    private Long promotionId;

    /**可退款金额*/
    @TableField(value = "refund_price")
    private Double refundPrice;

    /**
     * 评论状态:未评论(UNFINISHED),待追评(WAIT_CHASE),评论完成(FINISHED)
     */
    @TableField(value = "comment_status")
    private String commentStatus;

    public OrderItemsDO(){

    }

    /**
     * 订单货物构造器
     * @param skuVO
     */
    public OrderItemsDO(CartSkuVO skuVO){
        this.setGoodsId(skuVO.getGoodsId());
        this.setProductId(skuVO.getSkuId());
        this.setCatId(skuVO.getCatId());
        this.setImage(skuVO.getGoodsImage());
        this.setOrderSn(skuVO.getSkuSn());
        this.setName(skuVO.getName());
        this.setNum(skuVO.getNum());
        this.setPrice(skuVO.getPurchasePrice());
        List<SpecValueVO> specList = skuVO.getSpecList();
        String specJson = JsonUtil.objectToJson(specList);
        this.setSpecJson(specJson);
        this.setCommentStatus(CommentStatusEnum.UNFINISHED.name());

    }


    public OrderItemsDO(GoodsSkuVO skuVO) {
        this.setGoodsId(skuVO.getGoodsId());
        this.setProductId(skuVO.getSkuId());
        this.setCatId(skuVO.getCategoryId());
        this.setImage(skuVO.getThumbnail());
        this.setOrderSn(skuVO.getSn());
        this.setName(skuVO.getGoodsName());
        List<SpecValueVO> specList = skuVO.getSpecList();
        String specJson = JsonUtil.objectToJson(specList);
        this.setSpecJson(specJson);
        this.setCommentStatus(CommentStatusEnum.UNFINISHED.name());
    }
}
